package org.realogic.cfm.spring;

import java.sql.Time;

import org.springframework.core.convert.converter.Converter;

public class StringToTimeConverter implements Converter<String, Time> {

	public Time convert(String value) {
		Time temp = null;
		if (value != null && !value.trim().equals("") && !value.equals("null")) {
			try {
				if(value.length()==8){
					temp = Time.valueOf(value.trim());
				}
				else if(value.length()==5){
					temp = Time.valueOf(value.trim()+":00");
				}
				else if(value.length()==1 || value.length()==2){
					temp = Time.valueOf(value.trim()+":00:00");
				}
				else{
					temp = null;
				}
			} catch (Exception e) {
				temp = null;
			}
		}
		return temp;
	}
}
